<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=basePath%>resources/js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/js/jquery-2.1.4.min.js"></script>
<title>测试文件上传到fastdfs</title>
</head>
<script type="text/javascript">
	$(function(){
		$("#image").bind("click",function(){
			$("#file").click();
			$("#file").change(function(){
				$("#image").attr("src","<%=basePath%>resources/images/test2.png");
				uploadFile();
			})
		});
		
		/* $("#submit").bind("click",uploadFile); */
	})
	function uploadFile(){
	 	var filename = $("#file").val();
		if(filename==null||filename==''){
			alert("请先上传文件");
			return false;
		}
		$("#imgform").submit(); 	
	}
	function handle(msg) {
		alert(msg);
/*		var url = msg.data.url;
 		$("img[info=" + info + "]").attr("src", url);
		$("input[info=hidden_" + info + "]").val(url); */
		$("#image").attr("src",msg);
	}	
</script>
<body>
		<img alt="" src="http://10.0.0.115:8080/group1/M00/00/00/CgAAc1cM0AyAJk9bAAABsrM8N08777.png">
		<img alt="" src="<%=basePath%>resources/images/test1.png" id="image" name="image">
		<div style="display: none">
			<form class="form-horizontal" action="<%=basePath %>file/upload" method="post" id="imgform" target="imgiframe" enctype="multipart/form-data">
				<input type="file" name="file" id="file" />
			</form>
		</div>
	
		<div style="display: none">
			<iframe id="imgiframe" name="imgiframe"></iframe>
		</div>
</body>
</html>